//
//  Net.h
//
//  Created by SKY
//  Copyright © 翊sky. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AFURLSessionManager.h>

/**
 *  request success and then do
 *
 *  @param object the data server response
 */
typedef void(^SuccessBlock)(id object);
/**
 *  request fail and deal with it
 *
 *  @param error the message server reback
 */
typedef void(^FailureBlock)(NSError *error);
/**
 *  upload data and receive response
 *
 *  @param formData upload data
 */
typedef void(^FormDataBlock)(id<AFMultipartFormData> formData);
/**
 *  upload or download progress
 *
 *  @param progress 
 */
typedef void(^ProgressBlock)(NSProgress *progress);//上传或下载进度

@interface Net : NSObject

/**
 *  Request network data by get way
 *
 *  @param url          Request url
 *  @param view         ProgressView show in view
 *  @param success      A block When requset success, do other work in it
 *  @param failure      A block When requset fail, deal with it when error
 */
+ (void)getRequestHttpURL:(NSString *)url
                      view:(UIView *)view
             completation:(SuccessBlock)success;
/**
 *  Request network data by get way
 *
 *  @param url          Request url
 *  @param view         ProgressView show in view
 *  @param parameter    Requset data maybe use parameter
 *  @param success      A block When requset success, do other work in it
 *  @param failure      A block When requset fail, deal with it when error
 */
+ (void)postRequestHttpURL:(NSString *)url
                       view:(UIView *)view
                  parameter:(id)parameter
              completation:(SuccessBlock)success;

/**
 *  Upload data by post
 *
 *  @param url              Commit url
 *  @param parameter        Upload maybe use parameter
 *  @param uploadData       Commit data to server
 *  @param uploadProgress   Upload data progress
 *  @param success          A block When upload success, and receive response data, do other work in it
 *  @param failure          A block When upload fail, deal with it when error
 */
+ (void)postUploadHttpURL:(NSString *)url
                parameter:(id)parameter
                 formData:(FormDataBlock)uploadData
                 progress:(ProgressBlock)uploadProgress
             completation:(SuccessBlock)success
                  failure:(FailureBlock)failure;

/**
 *  Download data
 *
 *  @param url              Download url
 *  @param downloadProgress A block to show download progress
 *  @param success          Result when download success
 *  @param failure          Result when download fail
 */
+ (void)downloadWithURL:(NSString *)url
               progress:(ProgressBlock)downloadProgress
           completation:(SuccessBlock)success
                failure:(FailureBlock)failure;
@end
